home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
3576
/
3576.xpi
/
chrome
/
googleshortcuts.jar
/
content
/
googlebuttonsOverlay.js
next >
Wrap
Text File
|
2009-12-13
|
14KB
|
372 lines
if(!de) var de={};
if(!de.soerenrinne) de.soerenrinne={};
if(!de.soerenrinne.GoogleButtons) de.soerenrinne.GoogleButtons={};
de.soerenrinne.GoogleButtons = function(){
var pub = {};
googlebuttonsPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("de.soerenrinne.googlebuttons.");
var servicesList = googlebuttonsPrefs.getCharPref('wholeshebang');
var soerenrinneServicesArray = new Array();
soerenrinneServicesArray = servicesList.split(',');
soerenrinneServicesArray.sort(function(x,y){
var a = String(x).toUpperCase();
var b = String(y).toUpperCase();
if (a > b)
return 1
if (a < b)
return -1
return 0;
});
var soerenrinneNumberOfServices = soerenrinneServicesArray.length;
PrefListener = function(branchName, func)
{
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch(branchName);
branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.register = function()
{
branch.addObserver("", this, false);
branch.getChildList("", { })
.forEach(function (name) { func(branch, name); });
};
this.unregister = function unregister()
{
if (branch)
branch.removeObserver("", this);
};
this.observe = function(subject, topic, data)
{
if (topic == "nsPref:changed")
func(branch, data);
};
}
GoogleButtons_renew = function() {
try {
if (document.getElementById('GIcon') != null) {
document.getElementById('GIcon').hidden = true;
}
// Add toolbar items (if not added before)
if (document.getElementById("googlebuttonsOrientation") != null) {
var box = document.getElementById("googlebuttonsOrientation"); // a <menupopup> element
for (var j=0; j<soerenrinneNumberOfServices; j++) {
var id = soerenrinneServicesArray[j];
var idStripped = id.replace(/\ /g, "").toLowerCase();
if (googlebuttonsPrefs.getBoolPref(id) == true) {
var child = create_ToolbarButton(idStripped+"1", id, "false", "open_website(event, '" + id + "_url');");
} else {
var child = create_ToolbarButton(idStripped+"1", id, "true", "open_website(event, '" + id + "_url');");
}
if (document.getElementById(idStripped+"1") == null) {
box.insertBefore(child, box.lastChild);
}
}
}
// Add menu items (if not added before)
if (document.getElementById("googlebuttons_menupopup") != null) {
var menupopup = document.getElementById("googlebuttons_menupopup");
for (var j=0; j<soerenrinneNumberOfServices; j++) {
var id = soerenrinneServicesArray[j];
var idStripped = id.replace(/\ /g, "").toLowerCase();
if (googlebuttonsPrefs.getBoolPref(id) == true) {
var child = create_MenuItem(idStripped, id, "false", "open_website(event, '" + id + "_url');");
} else {
var child = create_MenuItem(idStripped, id, "true", "open_website(event, '" + id + "_url');");
}
if (document.getElementById(idStripped) == null) {
menupopup.insertBefore(child, menupopup.lastChild);
}
}
}
if (googlebuttonsPrefs.getBoolPref('dropdown') == true) {
if (document.getElementById('googlebuttonsOrientation') != null && document.getElementById('googlebuttonsdropdownmenu') != null)
{
document.getElementById('googlebuttonsOrientation').hidden = true;
document.getElementById('googlebuttonsdropdownmenu').hidden = false;
}
} else {
if (document.getElementById('googlebuttonsOrientation') != null && document.getElementById('googlebuttonsdropdownmenu') != null)
{
document.getElementById('googlebuttonsOrientation').hidden = false;
document.getElementById('googlebuttonsdropdownmenu').hidden = true;
}
}
for(var i=0;i<soerenrinneNumberOfServices;i++) {
var id = soerenrinneServicesArray[i];
var idStripped = id.replace(/\ /gi, "").toLowerCase();
try {
if (googlebuttonsPrefs.getBoolPref(id) == true)
{
if (document.getElementById(idStripped) != null)
document.getElementById(idStripped).hidden = false;
if (document.getElementById(idStripped+'1') != null)
document.getElementById(idStripped+'1').hidden = false;
}
else
{
if (document.getElementById(idStripped) != null)
document.getElementById(idStripped).hidden = true;
if (document.getElementById(idStripped+'1') != null)
document.getElementById(idStripped+'1').hidden = true;
}
} catch (e) {
alert("Error on inner switching in renew:\n" + e.name + ", " + e.message + "\nid: " + id + "\nidStripped: " + idStripped);
}
}
if (googlebuttonsPrefs.getBoolPref('settings') == true)
{
if (document.getElementById('settings1') != null)
document.getElementById('settings1').hidden = false;
if (document.getElementById('settings') != null)
document.getElementById('settings').hidden = false;
}
else
{
if (document.getElementById('settings1') != null)
document.getElementById('settings1').hidden = true;
if (document.getElementById('settings') != null)
document.getElementById('settings').hidden = true;
}
if (googlebuttonsPrefs.getBoolPref('orient_horizontally') == true)
{
if (document.getElementById('googlebuttonsOrientation') != null)
document.getElementById('googlebuttonsOrientation').orient = "horizontal";
}
else
{
if (document.getElementById('googlebuttonsOrientation') != null)
document.getElementById('googlebuttonsOrientation').orient = "vertical";
}
} catch (e) {
alert("Error on switching in renew:\n" + e.name + ", " + e.message);
}
}
pub.GoogleButtons_onLoad = function() {
// automatisch die toolbar hinzufⁿgen, wenn sie nicht schon da ist. Aber nur einmal!
if (googlebuttonsPrefs.getBoolPref('firstLoad')) {
try {
var firefoxnav = document.getElementById("nav-bar");
var curSet = firefoxnav.currentSet;
if (curSet.indexOf("GoogleShortcuts_button_set") == -1)
{
var set;
// Place the button before the urlbar
if (curSet.indexOf("urlbar-container") != -1)
set = curSet.replace(/urlbar-container/, "GoogleShortcuts_button_set,urlbar-container");
else // at the end
set = curSet + ",GoogleShortcuts_button_set";
firefoxnav.setAttribute("currentset", set);
firefoxnav.currentSet = set;
document.persist("nav-bar", "currentset");
// If you don't do the following call, funny things happen
try {
BrowserToolboxCustomizeDone(true);
}
catch (e) { alert("Error on automatic adding (inner try):\n" + e.name + ", " + e.message); }
}
googlebuttonsPrefs.setBoolPref('firstLoad', false);
}
catch(e) { alert("Error on automatic adding:\n" + e.name + ", " + e.message); }
}
try {
if (document.getElementById('GIcon') != null) {
document.getElementById('GIcon').hidden = true;
}
// Add toolbar items
if (document.getElementById("googlebuttonsOrientation") != null) {
var box = document.getElementById("googlebuttonsOrientation"); // a <menupopup> element
for (var j=0; j<soerenrinneNumberOfServices; j++) {
var id = soerenrinneServicesArray[j];
var idStripped = id.replace(/\ /g, "").toLowerCase();
if (googlebuttonsPrefs.getBoolPref(id) == true) {
var child = create_ToolbarButton(idStripped+"1", id, "false", "open_website(event, '" + id + "_url');");
} else {
var child = create_ToolbarButton(idStripped+"1", id, "true", "open_website(event, '" + id + "_url');");
}
if (document.getElementById(idStripped+"1") == null) {
box.insertBefore(child, box.lastChild);
}
}
}
// Add menu items
if (document.getElementById("googlebuttons_menupopup") != null) {
var menupopup = document.getElementById("googlebuttons_menupopup");
for (var j=0; j<soerenrinneNumberOfServices; j++) {
var id = soerenrinneServicesArray[j];
var idStripped = id.replace(/\ /g, "").toLowerCase();
if (googlebuttonsPrefs.getBoolPref(id) == true) {
var child = create_MenuItem(idStripped, id, "false", "open_website(event, '" + id + "_url');");
} else {
var child = create_MenuItem(idStripped, id, "true", "open_website(event, '" + id + "_url');");
}
if (document.getElementById(idStripped) == null) {
menupopup.insertBefore(child, menupopup.lastChild);
}
}
}
// now everything is added, let's see how it should look like
if(googlebuttonsPrefs.getBoolPref('dropdown') == true) {
if (document.getElementById('googlebuttonsOrientation') != null && document.getElementById('googlebuttonsdropdownmenu') != null)
{
document.getElementById('googlebuttonsOrientation').hidden = true;
document.getElementById('googlebuttonsdropdownmenu').hidden = false;
}
} else {
if (document.getElementById('googlebuttonsOrientation') != null && document.getElementById('googlebuttonsdropdownmenu') != null)
{
document.getElementById('googlebuttonsOrientation').hidden = false;
document.getElementById('googlebuttonsdropdownmenu').hidden = true;
}
}
if (googlebuttonsPrefs.getBoolPref('orient_horizontally') == true)
{
if (document.getElementById('googlebuttonsOrientation') != null)
document.getElementById('googlebuttonsOrientation').orient = "horizontal";
}
else
{
if (document.getElementById('googlebuttonsOrientation') != null)
document.getElementById('googlebuttonsOrientation').orient = "vertical";
}
} catch (e) {
alert("Error onLoad:\n" + e.name + ", " + e.message);
}
// generate observer
myListener = new PrefListener("de.soerenrinne.googlebuttons.",
function(branch, name)
{
GoogleButtons_renew();
});
myListener.register();
}
// First run function
pub.GoogleButtons_OpenFirstRunPage = function() {
var VERSION = "1.8.4";
var URL = "http://www.soerenrinne.de/GoogleShortcuts/update.html";
var pref = googlebuttonsPrefs;
if (!pref.prefHasUserValue("version")) {
//no version found
setTimeout(function() { window.openUILinkIn(URL, "tab"); }, 500);
pref.setCharPref("version", VERSION);
}
if (pref.getCharPref("version") != VERSION) {
//newer version
setTimeout(function() { window.openUILinkIn(URL, "tab"); }, 500);
pref.setCharPref("version", VERSION);
}
}
open_website = function(event, url) {
var btnCode = event.button;
var browser = document.getElementById("content");
var ctrlKey = event.ctrlKey;
var prefs_url = googlebuttonsPrefs.getCharPref(url);
var shiftKey = event.shiftKey;
var focustab = googlebuttonsPrefs.getBoolPref("focustab");
var alwaysNewTab = googlebuttonsPrefs.getBoolPref("openintab");
if(btnCode == 0) { // left mouse button
if(ctrlKey == true) {
if(shiftKey == true) {
// new tab without focus
browser.addTab(prefs_url);
} else {
// new tab with focus
browser.selectedTab = browser.addTab(prefs_url);
}
} else if(shiftKey == true) {
// open in new window
window.open(prefs_url);
} else if(alwaysNewTab == true && focustab == false) {
// new tab with focus
browser.selectedTab = browser.addTab(prefs_url);
} else if(alwaysNewTab == true) {
// new tab without focus
browser.addTab(prefs_url);
} else {
// open in current tab
browser.loadURI(prefs_url);
}
} else if(btnCode == 1) { // middle mouse button
if(shiftKey == true) {
// new tab without focus
browser.addTab(prefs_url);
} else if(focustab == true){
// new tab without focus
browser.addTab(prefs_url);
} else {
// new tab with focus
browser.selectedTab = browser.addTab(prefs_url);
}
}
}
open_settings = function()
{
window.openDialog('chrome://googlebuttons/content/googlebuttonsSettings.xul','Settings of Google Shortcuts','chrome,titlebar,toolbar,centerscreen,alwaysRaised,dialog=no,resizable,autostretch');
}
create_ToolbarButton = function(aButtonID, aButtonTooltiptext, aButtonHidden, aButtonOnclick) {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = document.createElementNS(XUL_NS, "toolbarbutton"); // create a new XUL toolbarbutton
item.setAttribute("id", aButtonID);
item.setAttribute("tooltiptext", aButtonTooltiptext);
item.setAttribute("hidden", aButtonHidden);
item.setAttribute("class", "iconbutton");
item.setAttribute("onclick", aButtonOnclick);
item.setAttribute("label", aButtonTooltiptext);
item.setAttribute("image", "chrome://googlebuttons/skin/" + aButtonID.replace("1", "") + ".gif");
return item;
}
create_MenuItem = function(aMenuID, aMenuTooltiptext, aMenuHidden, aMenuOnclick) {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = document.createElementNS(XUL_NS, "menuitem"); // create a new XUL menuitem
item.setAttribute("id", aMenuID);
item.setAttribute("tooltiptext", aMenuTooltiptext);
item.setAttribute("hidden", aMenuHidden);
item.setAttribute("class", "menuitem-iconic");
item.setAttribute("label", aMenuTooltiptext);
item.setAttribute("onclick", aMenuOnclick);
item.setAttribute("image", "chrome://googlebuttons/skin/" + aMenuID + ".gif");
return item;
}
return pub;
}();
window.addEventListener("load", de.soerenrinne.GoogleButtons.GoogleButtons_onLoad, false);
window.addEventListener("load", de.soerenrinne.GoogleButtons.GoogleButtons_OpenFirstRunPage, false);